// 需求：自定义hook函数，可以自动同步到本地LocalStorage
import { useEffect,useState } from "react";
export function useLocalStorage (key,defaultValue){
    const [message,setMessage] = useState(defaultValue)
    // 每次只要message变化，就会自动同步到本地ls一份
    useEffect(()=>{
        window.localStorage.setItem(key,message)
    },[message,key])
    return [message,setMessage]
}
const [message,setMessage] = useLocalStorage(key,defaultValue)